<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [1, 2, 3, 4, 5, 6, 1, 2, 3];
        /* 使用reduce方法实现数组元素求和 */
        const sum=arr.reduce(function (sum, item, index, arr) {
            return sum + item;
        }, 0);
        console.log(sum);
        /*  使用reduce方法实现求数组的最大值*/
        const max=arr.reduce(function (max, item, index, arr) {
            return Math.max(max, item);
        }, 0);
        console.log(max);
        /* 使用reduce方法实现数组去重 */
        const newArr=arr.reduce(function (newArr, item, index, arr) {
            newArr.indexOf(item) === -1 && newArr.push(item);
            return newArr;
        }, []);
        console.log(newArr);
    </script>
</body>

</html>